//
//  ZCTabBarController.m
//  百思不得姐
//
//  Created by Ning Xie on 16/8/24.
//  Copyright © 2016年 zhangchong. All rights reserved.
//

#import "ZCTabBarController.h"
#import "ZCEssenceViewController.h"
#import "ZCNewViewController.h"
#import "ZCFriendTrendsViewController.h"
#import "ZCMeTableController.h"
#import "ZCNavigationController.h"
#import "ZCTabBar.h"

@interface ZCTabBarController ()

@end

@implementation ZCTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    [SVProgressHUD setMinimumDismissTimeInterval:2];
    [self setupChildController];
}
+(void)initialize{
    
    UITabBarItem *item = [UITabBarItem appearance];
    [item setTitleTextAttributes:@{
                                   NSFontAttributeName : [UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName : [UIColor grayColor]
                                   } forState:UIControlStateNormal];
    [item setTitleTextAttributes:@{
                                   NSFontAttributeName : [UIFont systemFontOfSize:12],
                                   NSForegroundColorAttributeName : [UIColor blackColor]
                                   } forState:UIControlStateSelected];

}

/**
 *  添加子控制器
 */
-(void)setupChildController{
    
    [self addChildViewController:[[ZCEssenceViewController alloc]init] title:@"精华" image:@"tabBar_essence_icon" selectedImage:@"tabBar_essence_click_icon"];
    [self addChildViewController:[[ZCNewViewController alloc]init] title:@"新帖" image:@"tabBar_new_icon" selectedImage:@"tabBar_new_click_icon"];
    [self addChildViewController:[[ZCFriendTrendsViewController alloc]init] title:@"关注" image:@"tabBar_friendTrends_icon" selectedImage:@"tabBar_friendTrends_click_icon"];
    [self addChildViewController:[[ZCMeTableController alloc]init] title:@"我" image:@"tabBar_me_icon" selectedImage:@"tabBar_me_click_icon"];
    
    [self setValue:[[ZCTabBar alloc]init] forKeyPath:@"tabBar"];
}


/**
 *  添加自控制器方法
 *
 *  @param childController   自控制器名称
 *  @param title             tabBar名称
 *  @param imageName         tabBar图标(普通)
 *  @param selectedImageName tabBar图标(选中)
 */
-(void)addChildViewController:(UIViewController *)childController title:(NSString*)title image:(NSString*)imageName selectedImage:(NSString*)selectedImageName{
    
    [childController.tabBarItem setImage:[UIImage imageNamed:imageName]];
    [childController.tabBarItem setSelectedImage:[UIImage imageNamed:selectedImageName]];
    childController.tabBarItem.title = title;
    
    ZCNavigationController *nav = [[ZCNavigationController alloc]initWithRootViewController:childController];
    
    [self addChildViewController:nav];
    
}





@end
